package com.yundasys.lab10designpattern.template;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @PACKAGE_NAME: com.yundasys.lab10designpattern.template
 * @NAME: JdbcTemplateUserImpl
 * @USER: jiangta
 * @DATE: 2021/8/26
 * @TIME: 3:34 下午
 * @PROJECT_NAME: springboot-labs
 */
public class JdbcTemplateUserImpl extends JdbcTemplate {
    @Override
    protected Object doInStatement(ResultSet rs) {
        List<User> userList = new ArrayList<User>();

        try {
            User user = null;
            while (rs.next()) {

                user = new User();
                user.setId(rs.getInt("id"));
                user.setUserName(rs.getString("user_name"));
                user.setBirth(rs.getDate("birth"));
                user.setCreateDate(rs.getDate("create_date"));
                userList.add(user);
            }
            return userList;
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }
}
